import matplotlib.pyplot as plt
import pandas as pd

# 读取CSV文件
df = pd.read_csv('bilibili_videos.csv', encoding='utf-8')

# 计算每个视频分区的总播放量
section_play_counts = df.groupby('视频分类')['播放量'].sum()

# 找出播放量前十的视频分区
top_10_sections = section_play_counts.nlargest(10)

# 计算前十视频分区的播放量占比
total_play_count = top_10_sections.sum()
percentages = top_10_sections / total_play_count

# 绘制扇形图
plt.rcParams['font.sans-serif']=['SimHei']
plt.figure(figsize=(8, 8))
plt.pie(percentages, labels=percentages.index, autopct='%1.1f%%', startangle=140, colors=plt.cm.tab20.colors)
plt.axis('equal')  # 使饼图比例相等
plt.title('Top 10 视频分区播放量占比')
plt.show()
